with v8.Class_Value;
with Ada.Unchecked_Conversion;
package v8.Class_External is
   type External (<>) is new v8.Class_Value.Value with private;
   type Pointer is access all External;
   --  A JavaScript value that wraps a C++ void*.  This type of value is
   --  mainly used to associate C++ data structures with JavaScript
   --  objects.
   --
   --  The Wrap function V8 will return the most optimal Value object wrapping the
   --  C++ void*. The type of the value is not guaranteed to be an External object
   --  and no assumptions about its type should be made. To access the wrapped
   --  value Unwrap should be used, all other operations on that object will lead
   --  to unpredictable results.

   generic
      type T (<>) is limited private;
      type P is access all T;
   function Value (this : Pointer) return P;

   function Wrap (data : Address) return Pointer;

   function Unwrap (obj : v8.Class_Value.Pointer) return Address;

   generic
      type T (<>) is limited private;
      type P is access all T;
   function Create (value : P) return Pointer;

   function Cast is new Ada.Unchecked_Conversion (v8.Class_Value.Pointer, Pointer);
   -- Convert Value to External


private
   type External is new v8.Class_Value.Value with null record;


   pragma Import (CPP, Wrap, "_ZN2v88External4WrapEPv");
   pragma Import (CPP, Unwrap, "_Z15External_UnwrapN2v86HandleINS_5ValueEEE");
   pragma Import (CPP, Value, "_ZNK2v88External5ValueEv");
   pragma Import (CPP, Create, "_ZN2v88External3NewEPv");
end v8.Class_External;
